import asyncio
import os
import socket
from inspect import getmodule, stack, currentframe


class toolLog:
    @staticmethod
    def setUp(msg: str):
        async def asyncSetUp():
            udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            udp_socket.sendto(msg.encode('utf-8'), ('127.0.0.1', 5656))
            udp_socket.close()

        asyncio.run(asyncSetUp())

    @staticmethod
    def error(msg):
        toolLog.setUp(f"error:::{msg}:::{getmodule(stack()[1][0]).__file__}:::{str(currentframe().f_back.f_lineno)}:::{os.getpid()}")

    @staticmethod
    def warn(msg):
        toolLog.setUp(f"warn:::{msg}:::{getmodule(stack()[1][0]).__file__}:::{str(currentframe().f_back.f_lineno)}:::{os.getpid()}")

    @staticmethod
    def info(msg):
        toolLog.setUp(f"info:::{msg}:::{getmodule(stack()[1][0]).__file__}:::{str(currentframe().f_back.f_lineno)}:::{os.getpid()}")

    @staticmethod
    def Critical(msg):
        toolLog.setUp(f"Critical:::{msg}:::{getmodule(stack()[1][0]).__file__}:::{str(currentframe().f_back.f_lineno)}:::{os.getpid()}")
